package Service;

import Utils.QueryUtil;
import Utils.UpdateUtil;

import java.util.Scanner;

/**
 * @author 文永达
 * @title: UIService
 * @projectName jiaowuglxt
 * @description: TODO
 * @date 2021/1/20 12:51
 */
public class UIService {
    Scanner scanner = new Scanner(System.in);
    UpdateUtil update = new UpdateUtil();
    QueryUtil query = new QueryUtil();
    public void UI(){
        while (true){
            System.out.println("+-------------------+");
            System.out.println("|欢迎使用教务管理系统      |");
            System.out.println("|-------------------+");
            System.out.println("|1.开学添加新班                   |");
            System.out.println("|2.新生录入                      |");
            System.out.println("|3.按照班级查询学生                |");
            System.out.println("|4.统计每个班级学生总人数            |");
            System.out.println("|5.按照学生编号对学生降班            |");
            System.out.println("|6.按照学生编号对学生休学            |");
            System.out.println("|7.按照学生编号修改学生信息            |");
            System.out.println("|8.按照学生编号对学生复课            |");
            System.out.println("|9.按照学生编号可以查看每个学生的详细学习变动情况            |");
            System.out.println("|10.统计所有学生中事最多的学生            |");
            System.out.println("|11.根据编号调整某个学生的专业            |");
            System.out.println("|12.学生可以根据自己的学号查看自己的变动信息            |");
            System.out.println("|13.学生可以查看自己每个科目的成绩            |");
            System.out.println("|14.学生可以根据学号统计自己的一个学期的总成绩            |");
            System.out.println("|15.学生可以根据学号统计自己的一个学期的平均成绩            |");
            System.out.println("|16.学生可以根据学号查看自己一个学期的总绩点            |");
            System.out.println("|17.学生可以根据学科编号选择进行选修课选课            |");
            System.out.println("|18.退出系统            |");
            System.out.println("+-------------------+");
            System.out.println("|请输入你需要的功能：          |");
            System.out.println("+-------------------+");
            int ca = scanner.nextInt();
            switch (ca){
                case 1:
                    query.queryClazz();
                    System.out.println("请输入年级名称：");
                    String gradename1 = scanner.next();
                    System.out.println("请输入专业名称：");
                    String majorname1 = scanner.next();
                    System.out.println("请输入班级名称：");
                    String clazzname1 = scanner.next();
                    int num1 = update.addnewCLazz(majorname1,clazzname1,gradename1,1);
                    if(num1==0){
                        System.out.println("是否继续添加班级?y/n");
                        String s1 = scanner.next();
                        if (s1.equals("y")){
                            update.addnewCLazz(majorname1,clazzname1,gradename1,0);
                        }else {
                            break;
                        }
                    }
                    break;
                case 2:
                    System.out.println("请输入学生学号：");
                    String stunum2 = scanner.next();
                    System.out.println("请输入学生姓名：");
                    String stuname2 = scanner.next();
                    System.out.println("请输入学生性别：");
                    String stusex2 = scanner.next();
                    System.out.println("请输入学生年级：");
                    String gradename2 = scanner.next();
                    System.out.println("请输入学生专业：");
                    String majorname2 = scanner.next();
                    query.queryClazz(gradename2,majorname2);
                    System.out.println("请输入学生班级编号：");
                    int clazzid2 = scanner.nextInt();
                    update.addnewStudent(stunum2,stuname2,stusex2,clazzid2);
                    break;
                case 3:
                    query.queryClazz();
                    System.out.println("请输入班级编号：");
                    int clazzid3 = scanner.nextInt();
                    query.querystudentByClazz(clazzid3);
                    break;
                case 4:
                    query.queryClazz();
                    System.out.println("请输入班级编号：");
                    int clazzid4 = scanner.nextInt();
                    query.countStudentNumByClazz(clazzid4);
                    break;
                case 5:
                    System.out.println("请输入学生学号：");
                    String stunum5 = scanner.next();
                    int result5 =query.queryStudentBystunum(stunum5);
                    if(result5 == 1){
                        result5 = update.relegation(stunum5);
                        if(result5 == 1){
                            System.out.println("请选择你想要降的班：");
                            int clazzid5 = scanner.nextInt();
                            update.relegation(clazzid5,stunum5);
                            break;
                        }else {
                            break;
                        }
                    }else {
                        break;
                    }
                case 6:
                    System.out.println("请输入学生学号：");
                    String stunum6 = scanner.next();
                    int result6 =query.queryStudentBystunum(stunum6);
                    if (result6==1){
                        update.quitschool(stunum6);
                        break;
                    }else {
                        break;
                    }
                case 7:
                    System.out.println("请输入学生学号：");
                    String stunum7 = scanner.next();
                    int result7 = query.queryStudentBystunum(stunum7);
                    System.out.println("是否继续修改此学生信息？y/n");
                    String s2 = scanner.next();
                    if(result7==1&&s2.equals("y")){
                        System.out.println("是否修改学生学号？若是填写修改后的信息，不是则填n");
                        String stunum7_1 = scanner.next();
                        System.out.println("是否修改学生姓名？若是填写修改后的信息，不是则填n");
                        String stuname7_1 = scanner.next();
                        System.out.println("是否修改学生性别？若是填写修改后的信息，不是则填n");
                        String stusex7_1 = scanner.next();
                        update.updatestudent(stunum7_1,stuname7_1,stusex7_1,stunum7);
                        break;
                    }else if(result7==1){
                        System.out.println("已取消对此学生信息进行修改");
                        break;
                    }else
                        break;
                case 8:
                    System.out.println("请输入学生学号：");
                    String stunum8 = scanner.next();
                    int result8 = query.queryStudentBystunum(stunum8);
                    System.out.println("是否继续对此学生进行复课？y/n");
                    String s3 = scanner.next();
                    if(result8==1&&s3.equals("y")){
                        update.resumeschool(stunum8);
                        break;
                    }else if(result8==1){
                        System.out.println("已取消对此学生进行复课");
                        break;
                    }else {
                        break;
                    }
                case 9:
                    System.out.println("请输入学生学号：");
                    String stunum9 = scanner.next();
                    int result9 = query.queryStudentBystunum(stunum9);
                    if(result9==1){
                        query.thechangesofStudybyStunum(stunum9);
                        break;
                    }
                    break;
                case 10:
                    query.queryStuinfoAllStudent();
                    break;
                case 11:
                    System.out.println("请输入学生学号：");
                    String stunum11 = scanner.next();
                    int result11 = query.queryStudentBystunum(stunum11);
                    if(result11==1){
                        update.updateMajor(stunum11,0,0);
                        System.out.println("请输入需要转的专业的班级编号：");
                        int clazzid11 = scanner.nextInt();
                        update.updateMajor(stunum11,clazzid11,1);
                        break;
                    }
                    break;
                case 12:
                    System.out.println("请输入学生学号：");
                    String stunum12 = scanner.next();
                    int result12 = query.queryStudentBystunum(stunum12);
                    if(result12==1){
                        query.queryUpdateinfoBystunum(stunum12);
                        break;
                    }
                    break;
                case 13:
                    System.out.println("请输入学生学号：");
                    String stunum13 = scanner.next();
                    int result13 = query.queryStudentBystunum(stunum13);
                    if(result13==1){
                        query.queryScoreBystunum(stunum13);
                        break;
                    }
                    break;
                case 14:
                    System.out.println("请输入学生学号：");
                    String stunum14 = scanner.next();
                    int result14 = query.queryStudentBystunum(stunum14);
                    if(result14==1){
                        query.querySUMScoreBystunum(stunum14);
                        break;
                    }
                    break;
                case 15:
                    System.out.println("请输入学生学号：");
                    String stunum15 = scanner.next();
                    int result15 = query.queryStudentBystunum(stunum15);
                    if(result15==1){
                        query.queryAVGScoreBystunum(stunum15);
                        break;
                    }
                    break;
                case 16:
                    System.out.println("请输入学生学号：");
                    String stunum16 = scanner.next();
                    int result16 = query.queryStudentBystunum(stunum16);
                    if(result16==1){
                        query.querySUMPointBystunum(stunum16);
                        break;
                    }
                    break;
                case 17:
                    System.out.println("请输入学生学号：");
                    String stunum17 = scanner.next();
                    int result17 = query.queryStudentBystunum(stunum17);
                    if(result17==1){
                        query.queryOptionalCourse();
                        System.out.println("请输入您要选修的课程编号：");
                        int courseid = scanner.nextInt();
                        update.updateOptionalCourseBystunum(stunum17,courseid);
                        break;
                    }
                    break;
                case 18:
                    System.exit(0);
                    break;
                default:
                    System.out.println("编号输入错误！请重新输入");
                    break;
            }
        }

    }
}
